package sword_offer;

/**
 * @ClassName _15TheNumberOfOneInHamming
 * @Description: 输出二进制数字中1的个数
 * @Author: yongliang.ma
 * @Create_time:2022/10/10 13:20
 */
public class _15TheNumberOfOneInHamming {

    public static void main(String[] args) {
        int i = new _15TheNumberOfOneInHamming().hammingWeight(123);
        System.out.println(i);
    }

    // you need to treat n as an unsigned value
    public int hammingWeight(int n) {
        int count = 0;
        for (int i = 0; i < 32; i++) {
            if ((n & 1) != 0)
                count++;
           n = n >>> 1;
        }
        return count;
    }
}
